package com.zjitc.pigspring.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.zjitc.pigspring.bean.po.Goods;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface GoodsMapper extends BaseMapper<Goods>, MPJBaseMapper<Goods> {

    @Select("SELECT goods.`id`,goods.`name`,goods.`img`,goods.`description`,goods.`price`,goods.`unit`,goods.`count`,goods.`type_id`" +
            ",goods.`seller_id`,type.`name` AS TypeName,seller.`name` AS SellerName FROM goods LEFT JOIN type ON goods.`type_id`=type.`id`" +
            " LEFT JOIN seller ON seller.`id`=goods.`seller_id`")
    List<Goods> getGoodsList();

    @Select("SELECT goods.`id`,goods.`name`,goods.`img`,goods.`description`,goods.`price`,goods.`unit`,goods.`count`,goods.`type_id`" +
            ",goods.`seller_id`,type.`name` AS TypeName,seller.`name` AS SellerName FROM goods LEFT JOIN type ON goods.`type_id`=type.`id`" +
            " LEFT JOIN seller ON seller.`id`=goods.`seller_id` where goods.name like CONCAT('%',#{name},'%')")
    List<Goods> goodsQuery(Goods goods);

    @Select("SELECT goods.`id`,goods.`name`,goods.`img`,goods.`description`,goods.`price`,goods.`unit`,goods.`count`,goods.`type_id`" +
            ",goods.`seller_id`,type.`name` AS TypeName,seller.`name` AS SellerName FROM goods LEFT JOIN type ON goods.`type_id`=type.`id`" +
            " LEFT JOIN seller ON seller.`id`=goods.`seller_id` where goods.seller_id = #{id}")
    List<Goods> GoodsListBySeller(Integer id);

    @Select("select * from goods order by count desc limit 0,15")
    List<Goods> getTops();

    @Select("SELECT goods.`id`,goods.`name`,goods.`img`,goods.`description`,goods.`price`,goods.`unit`,goods.`count`,goods.`type_id`" +
            ",goods.`seller_id`,type.`name` AS TypeName,seller.`name` AS SellerName FROM goods LEFT JOIN type ON goods.`type_id`=type.`id`" +
            " LEFT JOIN seller ON seller.`id`=goods.`seller_id` where goods.seller_id = #{sellerId} and goods.name like CONCAT('%',#{name},'%')")
    List<Goods> goodsQueryBySeller(Goods goods);
}
